package com.zzl.car.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzl.car.entity.CarOrder;
import com.zzl.car.entity.Illegal;
import com.zzl.car.entity.Insurance;
import com.zzl.car.mapper.InsuranceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InsuranceService {

    @Autowired
    private InsuranceMapper insuranceMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    private String insuranceKey = "insuranceInUsing";

    /**
     *
     * @param id 保障服务id
     * @return 保障服务信息
     */
    public Insurance getInsuranceById(Integer id){
        return insuranceMapper.getInsuranceById(id);
    }


    public List<Insurance> getInsuranceInUsing() {
        List<Insurance> insurances = null;
        insurances = redisTemplate.opsForList().range(insuranceKey,0,-1);
        if(insurances.size()==0) {
            insurances = insuranceMapper.getAllInsuranceInUsing();
            redisTemplate.opsForList().rightPushAll(insuranceKey,insurances);
        }
        return insurances;

    }

}
